<template>
	<u-swiper keyName="image" :list="list" :radius="radius" :mode="model" @click="change" :height="height"
		:indicator="indicator" indicatorMode="dot" circular imgMode="heightFix" :previousMargin="previousMargin"
		:nextMargin="nextMargin" :autoplay="flag" @vPlay="play" @vEnded="ended" @vPause="pause"></u-swiper>
</template>

<script>
	import {
		goNav
	} from '@/lib/Comment.js'
	export default {
		name: "swiperList",
		props: {
			list: {
				type: Array,
				default: () => {
					return []
				}
			},
			radius: {
				type: Number,
				default: 0
			},
			model: {
				type: String,
				default: 'rect'
			},
			height: {
				type: String,
				default: '250rpx'
			},
			nextMargin: {
				type: Number,
				default: 0
			},
			previousMargin: {
				type: Number,
				default: 0
			},
			autoplay: {
				type: Boolean,
				default: true
			},
			indicator: {
				type: Boolean,
				default: true
			}
		},
		data() {
			return {
				flag: true
			};
		},
		mounted() {
			this.flag = this.autoplay
		},
		methods: {
			change: function(index) {
				let url = this.list[index].url
				if (url) {
					console.log('index>>>', url)
					// plus.statistic.eventTrig("slide_image", {
					// 	"path": url
					// });
					goNav(url)
				}
			},
			ended: function() {

				if (this.autoplay)
					this.flag = true
				console.log("播放结束", this.autoplay)

			},
			play: function() {
				console.log("播放开始", this.autoplay)
				if (this.autoplay)
					this.flag = false
			},
			pause: function() {

				if (this.autoplay)
					this.flag = true
			},

			async GetDomMaxHeight(targetClass) {
				try {
					if (targetClass) {
						//规定传入class 不需要加. 默认查询所有 
						let rectInfo = await uni.getRect('.' + targetClass, true);
						if (rectInfo?.length > 0) {
							console.log(rectInfo, '????')
							let MaxHeight = rectInfo.map(xitem => xitem.height).sort((a, b) => b - a)[0];
							return MaxHeight
						} else {
							console.log('传入的class错误')
							return 0
						}
					} else {
						console.log('传入的class错误')
						return 0
					}
				} catch (err) {
					console.log(err, 'GetDomMaxHeighterr_')
				}
			}

		}
	}
</script>

<style>

</style>
